import { Button, Popconfirm, Space } from 'antd';
import dayjs from 'dayjs';

export const columns = (editRuler, deleteRule, updateRuleStatus) => [
  {
    title:'index',
    dataIndex: 'index',
    key: 'index',
    width: 60,
    render: (_, { status },index) => <>{index+1}</>
  },
  // {
  //   title: 'id',
  //   dataIndex: 'uuid',
  //   key: 'uuid',
  //   width: 120,
  // },
  {
    title: '名称',
    dataIndex: 'name',
    key: 'name',
    width: 100,
  },
  {
    title: '类型',
    dataIndex: 'type',
    key: 'type',
    width: 80,
    render: (_, record) => {
      return DATASOURCE_TYPE_MAP[record.type] || '--'
    }
  },
  {
    title: '驱动名称',
    dataIndex: 'driverClassName',
    key: 'driverClassName',
    width: 150,
  },
  {
    title: '登录名',
    dataIndex: 'username',
    key: 'username',
    width: 100,
  },
  {
    title: '登录密码',
    dataIndex: 'password',
    key: 'password',
    width: 100,
  },
  {
    title: '配置信息',
    dataIndex: 'url',
    key: 'url',
    width: 300,
  },
  {
    title: '创建人',
    dataIndex: 'createdBy',
    key: 'createdBy',
    width: 130,
    render: (_) => _ ? _ : "--"
  },
  {
    title: '创建时间',
    dataIndex: 'createdAt',
    key: 'createdAt',
    width: 130,
    render: (_, record) => {
      return _ ? dayjs(_).format('YYYY-MM-DD HH:mm:ss') : '--'
    }
  },
  {
    title: '更新人',
    dataIndex: 'updatedBy',
    key: 'updatedBy',
    width: 130,
    render: (_) => _ ? _ : "--"
  },
  {
    title: '更新时间',
    dataIndex: 'updatedAt',
    key: 'updatedAt',
    width: 130,
    render: (_, record) => {
      return _ ? dayjs(_).format('YYYY-MM-DD HH:mm:ss') : '--'
    }
  },
  {
    title: '操作',
    key: 'action',
    width: 120,
    fixed: 'right',
    align:'center',
    render: (_, record) => (
      <Space size="middle">
        <Button type='primary' size='small' onClick={() => editRuler(record)}>编辑</Button>
        {/* <Popconfirm
          title={!record.status ? '开启当前数据源' : '暂停当前数据源'}
          description={!record.status ? '开启当前数据源' : '暂停当前数据源'}
          onConfirm={() => updateRuleStatus(!record.status ? true : false, record)}
          okText="确定"
          cancelText="取消"
        > <Button size='small' type={!record.status ? 'primary' : 'dashed'}>{!record.status ? '开启' : '暂停'}</Button>
        </Popconfirm> */}
        <Popconfirm
          title="删除当前数据源"
          description="继续删除当前数据源?"
          onConfirm={() => deleteRule(record.uuid)}
          // onCancel={deleteRule}
          okText="确定"
          cancelText="取消"
        >
          <Button size='small' danger disabled>删除</Button>
        </Popconfirm>
      </Space >
    ),
  },
];

export const KvMap = {
  true: {
    color: 'green',
    name: '开启',
  },
  false: {
    color: 'red',
    name: '关闭',
  },
}

export const DATASOURCE_TYPE_LIST =[
  { label: 'MYSQL', value: 1 },
  { label: 'ES', value: 2 },
]

export const DATASOURCE_TYPE_MAP ={
  1:"MYSQL",
  2:"ES",
}
